import Vue from 'vue'
import Vuex from 'vuex'
import { getAllCategory } from '@/api/category'
Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    article: {
      title: '',
      content: '',
      category: '',
      tags: [],
      tabloid: '',
      type: true,
      author: '',
      newCategory: '',
      status: '',
      reprintURL: '',
      id: '',
      coverImg: ''
    },
    isUpdate: false,
    categories: getAllCategory()
  },
  mutations: {
    // 设置数据
    updateIsUpdate(state, isUpdate) {
      state.isUpdate = isUpdate
    },
    updateArticle(state, article) {
      state.article = article
      console.log('0000000000000000')
      console.log(state.article)
    },
    resetArticle(state, article) {
      state.article.title = ''
      state.article.content = ''
      state.article.category = ''
      state.article.tags = []
      state.article.tabloid = ''
      state.article.type = true
      state.article.author = ''
      state.article.newCategory = ''
      state.article.status = ''
      state.article.reprintAddress = ''
      state.isUpdate = false
      state.article.coverImg = ''
      state.article.id = ''
    }
  },
  getters: {
    getArticle(state) {
      return state.article
    },
    getIsUpdate(State) {
      return State.isUpdate
    }
  },
  actions: {}
})
export default store
